# cmake_uninstall.cmake.in

# 不会删除空目录版本
# ------------------------------------------------------------
if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
    message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif()

file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")

foreach(file ${files})
	set(full_path "$ENV{DESTDIR}${file}")  # 处理 DESTDIR 前缀
    message(STATUS "Uninstalling: ${full_path}")
    # 检查路径是否存在或是否是软链接
    if(EXISTS "${full_path}" OR IS_SYMLINK "${full_path}")
        # 使用 CMake 内置命令删除（兼容文件和软链接）
        file(REMOVE "${full_path}")

        # 可选：验证是否删除成功
        if(EXISTS "${full_path}" OR IS_SYMLINK "${full_path}")
            message(FATAL_ERROR "Failed to remove: ${full_path}")
        endif()
    else()
        message(STATUS "File '${full_path}' does not exist")
    endif()
endforeach()

# 删除空目录版本(先用shell脚本检测，后面熟练了cmake再说...)
# ------------------------------------------------------------
# TODO...